//
//  UseRedenvelopesTopView.m
//  NewPro
//
//  Created by RYX on 2019/6/25.
//  Copyright © 2019 何荧红. All rights reserved.
//

#import "UseRedenvelopesTopView.h"
#import "MyRedenvelopesList.h"
#import "MyRedenvelopesModel.h"

@implementation UseRedenvelopesTopView

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = UIColor.whiteColor;
        [self setUI];
    }
    return self;
}

- (void)setUI{
    
    UILabel *la = [[UILabel alloc] init];
    la.textColor = [UIColor colorWithHexString:@"383838"];
    la.font = [UIFont systemFontOfSize:14];
    la.text = @"不使用红包";
    [self addSubview:la];
    [la mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(14);
        make.top.bottom.mas_equalTo(0);
    }];
    
    UIView *line = [[UIView alloc] init];
    [self addSubview:line];
    line.backgroundColor = [UIColor lightGrayColor];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
    }];
    
    UIButton *btn = [[UIButton alloc] init];
    self.btn = btn;
    [btn setImage:[UIImage imageNamed:@"userRedBg_normal"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"userRedBg_selected"] forState:UIControlStateSelected];
    [self addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-29);
        make.width.height.mas_equalTo(20);
        make.centerY.equalTo(la);
    }];
    
    UIButton *tapBtn = [[UIButton alloc] init];
    [tapBtn addTarget:self action:@selector(onBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:tapBtn];
    [tapBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
    
}

- (void)onBtn:(UIButton *)btn{
    
    self.btn.selected = YES;
    
    MyRedenvelopesModel *model = [[MyRedenvelopesModel alloc] init];
    model.uid = @"-1";
    
    [MyRedenvelopesList sharedInstance].selectedRedenvelopes = model;
    
    if (self.onNoUseBtnBlock != nil) {
        
        self.onNoUseBtnBlock();
    }
}

- (void)returnBlock:(OnNoUseBtnBlock)block{
    
    self.onNoUseBtnBlock = block;
}
@end
